﻿using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class UIAB50 : UIABPOS
    {
        #region ==SQTY===========
        public static readonly DependencyProperty SQTYProperty = DependencyProperty.Register("SQTY",
            typeof(double), typeof(UIAB50),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSQTYChanged));
        public double SQTY
        {
            get
            {
                return (double)GetValue(SQTYProperty);
            }
            set
            {
                SetValue(SQTYProperty, value);
            }
        }
        private static void OnSQTYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAB50;
            if (src != null)
            {
                src.SQTY = (double)e.NewValue;
            }
        }
        #endregion

        #region ==YARN===========
        public static readonly DependencyProperty YARNProperty = DependencyProperty.Register("YARN",
            typeof(string), typeof(UIAB50),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnYARNChanged));
        public string YARN
        {
            get
            {
                return (string)GetValue(YARNProperty);
            }
            set
            {
                SetValue(YARNProperty, value);
                OnYARNChg();
            }
        }
        private static void OnYARNChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIAB50;
            if (src != null)
            {
                src.YARN = (string)e.NewValue;
            }
        }
        public virtual void OnYARNChg()
        { }
        #endregion

        public UIAB50()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }
        public virtual void RefreshARTCommand(object sender, RoutedEventArgs e)
        {
        }

        public void CHGAB50ART(Dictionary<string,object>pm)
        {
            try
            {
                DataRow dwABP = (DataRow)pm["dwABP"];
                if (dwABP == null)
                {
                    MessageBox.Show("请确认粗纱单");
                    return;
                }
                if (dwABP["ABPPOSTYP"].ToString().Trim() != "HM")
                {
                    MessageBox.Show("请选择粗纱单,而不是其他单");
                    return;
                }
                TMV.UABP09(dwABP);
                dwData = TMV.VMU.TBMain.NewRow();
                dwData["ABAMANDANT"] = app.Mandant;
                dwData["ABAVKAUFTYP"] = "V";
                dwData["ABAAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["ABAAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["ABAAUFPOS"] = dwABP["ABPAUFPOS"];
                SResult = TMV.VMU.QMU16(dwData);
                dwData = TMV.VGD.TBMain.NewRow();
                foreach (DataRow dwMU in SResult.Tables[0].Rows)
                {
                    dwData["GAMANDANT"] = dwMU["ABAMANDANT"];
                    dwData["GAAUFKRS"] = dwMU["ABAVKAUFKRS"];
                    dwData["GAAUFLFD"] = dwMU["ABAVKAUFLFD"];
                    dwData["GAAUFPOS"] = dwMU["ABAVKAUFPOS"];
                    dwData["GASA"] = "713";
                    dwData["GAPOS"] = dwMU["ABAVKUPOS"];
                    dwData["GAART"] = pm["ABPART"];
                    dwData["GAVAR"] = pm["ABAVAR"];
                    dwData["GAFARBE"] = pm["ABAFARBE"];
                    TMV.VGD.UGD16(dwData);
                }
                dwData = TMV.VABAX.TBMain.NewRow();
                dwData["ABAAUFKRS"] = dwABP["ABPAUFKRS"];
                dwData["ABAAUFLFD"] = dwABP["ABPAUFLFD"];
                dwData["ABAAUFPOS"] = dwABP["ABPAUFPOS"];
                dwData["ABAART"] = (string)pm["ABPART"];
                dwData["ABAVAR"] = (string)pm["ABAVAR"];
                dwData["ABAFARBE"] = (string)pm["ABAFARBE"];
                TMV.VABAX.UABAX02(dwData);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
    }
   
}
